package com.sz.freemusic.common;

import com.sz.freemusic.net.cache.BitmapCache;

import android.app.ActivityManager;
import android.content.Context;
import android.util.Log;

public final class ApplicationData {

	private static ApplicationData app_data_instance = null;
	
	private String applicationKey = "3729WR4VCPOLQ98E";
	
	private Context context = null;
	
	private BitmapCache bitmapCache;

	private String apiURL = "http://freemusicarchive.org/api/get/";
	
	private int thWidth;
	private int thHeight;
	
	private ApplicationData() {
		
	}
	
	public static ApplicationData getInstance() {
			synchronized (ApplicationData.class) {
				if (app_data_instance == null) {
					app_data_instance = new ApplicationData();
				}
			}
		return app_data_instance;
	} 
	
	public void initBitmapCache() {
		if (context == null) {
			Log.e("ApplicationData", "Cannot init BitmapCache, no Context was set in ApplicationData");
			return;
		}
		final int memClass = ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
		final int cacheSize = 1024 * 1024 * memClass / 8;
		bitmapCache = new BitmapCache(cacheSize);
	}
	
	public BitmapCache getBitmapCache() {
		if (bitmapCache == null) {
			throw new RuntimeException("BitmapCache was not initialized!");
		}
		return bitmapCache;
	}
	
	public void setContext(Context context) {
		this.context = context;
	}
	
	public String getAppKey() {
		return this.applicationKey;
	}
	
	
	public String getApiURL() {
		return apiURL ;
	}

	public int getThWidth() {
		return thWidth;
	}

	public void setThSize(int thWidth, int thHeight) {
		if (thHeight == 0 && thHeight == 0) {
			this.thWidth = thWidth;
			this.thHeight = thHeight;
		}
	}

	public int getThHeight() {
		return thHeight;
	}
	
	

	
}
